<template>
    <div class="goods_list">
        <div class="goods_item" v-for="item in goodslist" :key="item.id" @click="godetail(item.id)">
            <img :src="item.img_url" alt="">
            <h3>{{item.title}}</h3>
            <div class="goods_title">
                 <span class="new">¥{{item.sell_price}}</span>  <span class="old">¥{{item.market_price}}</span>
                <p>
                     <span>热卖中</span>  <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div>


        <!-- 加载更多 -->
        <mt-button type="danger" size="large" @click="load_more">加载更多</mt-button>
    </div>
</template>

<script>
import { Toast } from 'mint-ui'
export default {
    data(){
        return {
            goodslist:[],
            pageindex: 1
        }
    },
    methods:{
        // 获取商品列表
       getgoods(){
           this.$http.get('api/getgoods?pageindex='+this.pageindex).then(result=>{
               if(result.body.status === 0) {
                    this.goodslist = this.goodslist.concat(result.body.message)
                } else {
                    Toast('获取商品列表失败')
                }
           })
        },
       // 加载更多按钮事件
        load_more(){
            this.pageindex++
            // 调用加载评论方法
            this.getgoods()
        },
        // 跳转导航
        godetail(id){
            this.$router.push({name:'goodsinfo',params:{goodsid:id}})
        }
    },
    created(){
        this.getgoods()
    }
}
</script>

<style lang="less" scoped>
.goods_list{
  display: flex;
  flex-wrap: wrap;
  padding: 7px;
  justify-content: space-between;
//   background-color: #eee;
    .goods_item {
        margin-bottom: 10px;
        width: 49%; 
        border: 1px solid #ccc;
        box-shadow: 0 0 9px #999;
        // min-height: 293px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        img {
            width: 100%;
        }
        h3 {
            font-size: 16px;
        }
        .goods_title{
            padding: 5px;
            color: gray;
            background-color:#eee;
            .new{
                color: red;
                font-size: 14px;
                font-weight: 700;
            }
            .old{
                text-decoration: line-through;
                font-size: 10px;
            }
            p {
                display: flex;
                justify-content: space-between;
            }
        }
    }
}

</style>